<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en">
<head>
<title>系统通知管理</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="icon" href="favicon.ico" type="image/x-icon" />
<!-- END META SECTION -->

<!-- CSS INCLUDE -->        
      
<link rel="stylesheet" href="${ctx}/rs/js/zTree/css/zTreeStyle/metro.css"/>
<link rel="stylesheet" href="${ctx}/rs/css/bootstrap-table.css" />
<link rel="stylesheet" href="${ctx}/rs/css/main.css" />
<link id="theme" rel="stylesheet" href="${ctx}/rs/joli/css/theme-default.css" />

<!-- EOF CSS INCLUDE -->        
</head>
<body>

    <!-- START PAGE CONTAINER -->
      <div class="page-container">
        <!-- 引入左菜单部分 -->
          <jsp:include page="../joli/menu.jsp"></jsp:include>
          
          <!-- START PAGE CONTENT -->
          <div class="page-content">
              <jsp:include page="../joli/top.jsp"></jsp:include>
              
              <!-- START BREADCRUMB -->
              <ul class="breadcrumb">
                  <li><a href="#">系统管理</a></li>                    
                  <li class="active">系统通知管理</li>
              </ul>
              <!-- END BREADCRUMB -->   
              
              
              <!-- PAGE CONTENT WRAPPER -->
              <div class="page-content-wrap">
                <div class="row">
                    <div class="col-xs-12">
                        <div id="toolbar">
<!--                             <shiro:hasPermission name="notice:send"> -->
                                <button class="btn btn-info btn-sm srt-btn icon-send" onclick="add()">发布通知</button>
<!--                             </shiro:hasPermission> -->
                            <div class ="fr pb10">
                             状态:
                                    <select class="srt-put1 mr10 widput1" id="status" name ="status" onchange="refresh()">
                                    <option value="">全部</option>
                                    <option value="0">关闭</option>
                                    <option value="1">开启</option>
                                    <option value="2">过期</option>
                                </select>
                                 <button class="btn btn-primary btn-sm srt-btn active" onclick="refresh()">搜索</button>
                            </div>
                        </div>
                        <table id="table" cellpadding="0" cellspacing="0" data-toggle="table" data-toolbar="#toolbar"
                            data-url="${ctx}/notice/noticeMessList.htm"
                            data-cache="false"
                            data-pagination="true" 
                            data-side-pagination="server"
                            data-page-list="[10, 20, 50, 100]"
                            data-page-size="20"  
                            data-query-params="queryParams">
                            <thead>
                                <tr class="tab-th">
                                    <th data-field="id">编号</th>
                                    <th data-field="notice_position" class="col-md-2" data-formatter="positionFormatter">通知位置</th>
                                    <th data-field="notice_content" class="col-md-4">通知内容</th>
                                    <th data-field="date" data-formatter="timeFormatter">通知期限</th>
                                    <th data-field="status" data-formatter="statusFormatter">状态</th>
                                    <th data-field="action" class="col-md-2" data-formatter="actionFormatter">操作</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
              </div>
        </div>
     </div>

    <!-- 引入所有joli的脚本 -->
    <jsp:include page="../joli/scripts.jsp"></jsp:include>
    <!-- 引入页面需要的脚本 -->
    <script type="text/javascript" src="${ctx}/rs/js/bootstrapQ.min.js"></script>
    <script src="${ctx}/rs/js/zTree/js/jquery.ztree.all-3.5.min.js"></script>
    <script src="${ctx}/rs/js/bootstrap-table.js"></script>
    <script src="${ctx}/rs/js/bootstrap-table-zh-CN.js"></script>
    <script src="${ctx}/rs/js/jquery.formatDate.js"></script>
    <script src="${ctx}/rs/js/my97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/rs/js/session-out-error.js"></script>
    <script>
        activeMenu($("#menu_sys_7"));
        var $table = $('#table');
        
        $table.on('click-row.bs.table', function (e, row, $element) {
            $table.bootstrapTable('uncheckAll');
            $table.bootstrapTable('check', $element.index());
        });
        
        $table.bootstrapTable({
            height: getHeight()
        });
        
        //获取分辨率高度
        function getHeight() {
            return window.screen.height - 308;
        }
        
        $(window).resize(function () {
            $table.bootstrapTable('resetView',{height: getHeight()});
        });
        //初始化刷新
       function refresh(pageIndex,selectPage){
            var status =$("#status").val();
        	if(!pageIndex && !selectPage){
                pageIndex = 0;
                selectPage = 0;
            }
            var pageSize = $table.bootstrapTable('getOptions').pageSize;
            pageIndex=pageIndex*pageSize;
            $table.bootstrapTable('refresh', {
                silent: true,
                cache : false,
                url: '${ctx}/notice/noticeMessList.htm',
                query: {
                	status:status,
                    pageIndex : pageIndex,
                    pageSize : pageSize
                }
            });
            $table.bootstrapTable('selectPage', selectPage);
        }
       function timeFormatter(value, row, index){
           var start_time=row.start_time;
           var end_time= row.end_time;
           if(start_time!='' && start_time!=null){
           start_time = $.formatDate("yyyy-MM-dd HH:mm:ss", new Date(start_time));
           end_time = $.formatDate("yyyy-MM-dd HH:mm:ss", new Date(end_time));
           return  "<span class='label label-warning'>"+start_time+"至"+end_time+"</span>"
           }
           
           else{
            return "--";
           }
       }

       function positionFormatter(value, row, index){
           var retbak="";
           switch(row.notice_position){
           case "1":
               retbak="<span class='label label-info'>广告主平台</span>";
               break;
           case "2":
               retbak="<span class='label label-info'>媒体主平台</span>";
               break;
           case "3":
               retbak="<span class='label label-info'>平台首页</span>";
               break;
           case "4":
               retbak="<span class='label label-info'>邮件通知媒体主</span>";
               break;
           case "5":
               retbak="<span class='label label-info'>邮件通知广告主</span>";
               break;
           
           case "6":
               retbak="<span class='label label-info'>邮件通知广告代理商</span>";
               break;
           }
           return retbak;
       }
       
       function actionFormatter(value, row, index){
           var retbak="";
           switch(row.status){
       
           case "2":
               retbak='<a class="mr15" href="javascript:removeData('+row.id+')">删除</a>';
               break;
           case "0":
               retbak='<a class="mr15" href="javascript:open('+row.id+',1)">开</a><a class="mr15" href="javascript:edit('+row.id+')">编辑</a><a class="mr15" href="javascript:removeData('+row.id+')">删除</a>';
               break;
           case "1":
               retbak='<a class="mr15" href="javascript:open('+row.id+',0)">关</a><a class="mr15" href="javascript:edit('+row.id+')">编辑</a><a class="mr15" href="javascript:removeData('+row.id+')">删除</a>';
               break;
           }
           return retbak;
       }
       function statusFormatter(value, row, index){
           var retbak="";
           switch(row.status){
           case "1":
               retbak="开启"
               break;
           case "2":
               retbak="过期"
               break;
           case "0":
               retbak="关闭"
               break;
           }
           return retbak;
       }
        //发布通知
        function add() {
            var pageNumber = $table.bootstrapTable('getOptions').pageNumber;
            var pageIndex = pageNumber - 1;
            bootstrapQ.dialog({
                url : '${ctx}/notice/add.htm',
                title : '发布通知',
                width: "720px",
                close : 'true',
                hidebtn : 'true'
            },function(){
                //回调触发关闭窗口
                $("#bsmodal").modal("hide");
                refresh(pageIndex,pageNumber);
            });
        };
        
        function edit(id) {
            var pageNumber = $table.bootstrapTable('getOptions').pageNumber;
            var pageIndex = pageNumber - 1;
                bootstrapQ.dialog({
                    url : "${ctx}/notice/edit.htm?id="+ id,
                    title : "编辑系统通知",
                    close : 'true',
                    hidebtn : 'true'
                },function(){
                    //回调触发关闭窗口
                    $("#bsmodal").modal("hide");
                    refresh(pageIndex,pageNumber);
                });
        }
        
        function removeData(id) {
        	var pageNumber = $table.bootstrapTable('getOptions').pageNumber;
            var pageIndex = pageNumber - 1;
            var rows = $table.bootstrapTable('getSelections');
            var len=$("#table tbody").find("tr").length;
            if(len==rows.length){
                pageIndex = pageIndex - 1;
            }
            if(rows.length > 0){
                bootstrapQ.confirm('确定删除选中记录？',function(){
                    $.ajax({
                        url: "${ctx}/notice/delete.htm?id="+id,
                        success: function (text) {
                            bootstrapQ.msg({
                                msg  : '删除成功！',
                                type : 'success',
                                time : 2000
                            });
                            alert("删除成功");
                            refresh(pageIndex,pageNumber);
                        },
                        error: function () {
                            bootstrapQ.msg({
                                msg  : '删除失败！',
                                type : 'danger',
                                time : 2000
                            });
                            alert("删除失败")
                            refresh(pageIndex,pageNumber);
                        }
                    });
                });
            }
            }
        

        function queryParams(params) {
            return {
                pageIndex : params.offset,
                pageSize : params.limit
            };
        }
     
//         更改状态
        function open(id,status){
        	   $.ajax({
                url: "${ctx}/notice/open.htm",
               type: 'POST',
               data: {
                   id:id,
                   status:status
               },
                 success: function (text) {
                     bootstrapQ.msg({
                         msg  : '操作成功！',
                         type : 'success',
                         time : 2000
                     });
                     setTimeout("window.location.reload(true)",1000);
                 },
                 error: function () {
                     bootstrapQ.msg({
                         msg  : '操作失败！',
                         type : 'danger',
                         time : 2000
                     });
                     setTimeout("window.location.reload(true)",1000);
                 }
             });
        }
    </script>
</body>
</html>